﻿using BigEgg.Framework.Foundation;
using BigEgg.Framework.UnitTesting;
using FMStudio.Domain.Properties;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using System;

namespace FMStudio.Domain.SQLite.Test
{
    [TestClass]
    public class AuditBillTest
    {
        [TestMethod]
        public void GeneralAuditBillTest()
        {
            AuditBill auditBill = new AuditBill();

            Assert.IsNotNull(auditBill.ID);
            Assert.AreEqual(0, auditBill.Index);
            Assert.AreEqual(1.0, auditBill.Price);
            Assert.AreEqual(DateTime.Today, auditBill.Date);
            Assert.IsNull(auditBill.AuditType);

            AuditType auditType = new AuditType();
            auditBill.AuditType = auditType;

            Assert.AreEqual("", auditBill.Validate());
        }

        [TestMethod]
        public void AuditBillAuditTypePropertyChangedTest()
        {
            AuditBill auditBill = new AuditBill();
            Assert.IsNull(auditBill.AuditType);

            AuditType auditType = new AuditType();
            AssertHelper.PropertyChangedEvent(auditBill, x => x.AuditType, () => auditBill.AuditType = auditType);
            Assert.AreEqual(auditType, auditBill.AuditType);
        }
        
        [TestMethod]
        public void AuditBillTypeValidationTest()
        {
            AuditBill auditBill = new AuditBill();

            Assert.IsNull(auditBill.AuditType);
            Assert.AreEqual(Resources.AuditTypeMandatory, auditBill.Validate("AuditType"));

            AuditType auditType = new AuditType();
            auditBill.AuditType = auditType;
            Assert.AreEqual("", auditBill.Validate("AuditType"));
        }

        [TestMethod]
        public void AuditBillPriceValidationTest()
        {
            AuditBill auditBill = new AuditBill();

            Assert.AreEqual(1.0, auditBill.Price);

            auditBill.Price = 0.1;
            Assert.AreEqual("", auditBill.Validate("Price"));
            auditBill.Price = 0.0;
            Assert.AreEqual(Resources.AuditBillPriceGreater, auditBill.Validate("Price"));
            auditBill.Price = -0.1;
            Assert.AreEqual(Resources.AuditBillPriceGreater, auditBill.Validate("Price"));
        }
    }
}